/*
===========================================================================
Copyright (C) 2013-2014 Avotu Briezhaudzetava

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

===========================================================================
*/

#ifndef USERENTRY_H
#define USERENTRY_H

//
// includes
//
#include "databaseentry.h"
#include "common.h"

//
// class: UserEntry
//
class UserEntry : public DatabaseEntry {
    Q_PROPERTY( QString name READ name WRITE setName )
    Q_PROPERTY( QString password READ password WRITE setPassword )
    Q_PROPERTY( Flags flags READ flags WRITE setFlags )
    Q_FLAGS( Flags Flag )

public:
    // flags
    enum Flag {
        NoFlags   = 0x00,
        User      = 0x01,
        Superuser = 0x02,
        Disabled  = 0x04
    };
    Q_DECLARE_FLAGS( Flags, Flag )

    // constructor/destructor
    explicit UserEntry( const QSqlRecord &record, const QString &table );
    ~UserEntry();

    // props
    QString name() const { return this->record().value( "name" ).toString(); }
    QString password() const { return this->record().value( "password" ).toString(); }
    Flags flags() const { return static_cast<Flags>( this->record().value( "flags" ).toInt()); }

public slots:
    void setName( const QString &name ) { this->setValue( "name", name ); }
    void setPassword( const QString &password ) { this->setValue( "password", password ); }
    void setFlags( Flags flags ) { this->setValue( "flags", static_cast<int>( flags )); }
};

#endif // USERENTRY_H
